<template>
   <div class="produce-in-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      size="mini"
      align="center"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="id"
        min-width="70"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="order"
        label="采购单号"
        min-width="110"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="all_price"
        label="采购金额"
        min-width="80"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="make_username"
        label="制单人"
        min-width="70"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="purchase_name"
        label="采购员"
        min-width="90"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="date"
        label="时间"
        min-width="90"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="date"
        label="预计到货日期"
        min-width="110"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="status"
        label="状态"
        min-width="70"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="remarks"
        label="备注"
        min-width="90"
        align="center">
      </el-table-column>

      <el-table-column label="操作"
      min-width="290"
      align="center">
        <template slot-scope="scope">
          
          <template v-if="scope.row.status==='待下单'">
            <el-button
              size="mini"
              plain
              type="success"
              @click="ckeck(scope.row)">明细</el-button>
            <el-button
              size="mini"
              plain
              type="info"
              @click="tableEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              plain
              type="danger"
              @click="del(scope.row)">删除</el-button>
          </template>

          <template v-if="scope.row.status==='待入库'||scope.row.status==='部分入库'">
            <el-button
              size="mini"
              plain
              type="success"
              @click="ruku(scope.row)">入库</el-button>
            <el-button
              size="mini"
              plain
              type="info"
              @click="ckeck(scope.row)">查看</el-button>
            <el-button
              size="mini"
              plain
              type="primary"
              @click="tableEdit(scope.row)">编辑</el-button>
            <el-button
              size="mini"
              plain
              type="danger"
              @click="del(scope.row)">删除</el-button>
          </template>

          <template v-if="scope.row.status==='已入库'">
            <el-button
              size="mini"
              plain
              type="warning"
              @click="tuihuo(scope.row)">退货</el-button>
            <el-button
              size="mini"
              plain
              type="primary"
              @click="ckeck(scope.row)">查看</el-button>
          </template>

          <template v-if="scope.row.status==='已出货'||scope.row.status==='已作废'">
            <el-button
              size="mini"
              plain
              type="primary"
              @click="ckeck(scope.row)">查看详情</el-button>
          </template>

        </template>
      </el-table-column>
    </el-table>
    <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import ajaxResquest from '@/api/apiRequest';
import deleteConfirm from '@/components/deleteConfirm.vue';

@Component({
  components: {
    deleteConfirm
  }
})
export default class ProduceInTable extends Vue {
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask: boolean = false;
  deleteRes!: ajaxResquest;
  deleteId!: number;
  mounted() {
    this.deleteRes = new ajaxResquest('/purchase/delPurchaseOrder');
  }
  tableRowClassName({ row, rowIndex }: any) {
    if (row.colour === 'red') {
      return 'warning-row';
    }
  }
  ckeck(row: any) {
    console.log(row);
    this.$to('supplierOrderCheck', { id: row.id, status: row.status });
  }
  ruku(row: any) {
    console.log(row.id);

    this.$to('supplierToStroke', { id: row.id });
  }
  del(row: any) {
    this.deleteId = row.id;
    this.showMask = true;
  }
  closeDelete() {
    this.showMask = false;
  }
  deleteConfirm() {
    this.deleteRes
      .getFunction({ purchaseInfoId: this.deleteId })
      .then((res: any) => {
        if (res.data.code === 1) {
          this.showMask = false;
        }
        this.getData();
      });
  }
  tuihuo(row: any) {
    this.$to('supplierReturnCreate', { id: row.id });
  }
  tableEdit(row: any) {
    console.log(row);
    this.$to('supplierOrderCreate', { edit: true, id: row.id });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style lang="less">
</style>
